<template>
  <view class="container">
    <view class="header">
      <view style="display: flex; justify-content: space-evenly; align-items: center; height: 75rpx; line-height: 75rpx">
        <view :class="{ common: true, act: index == 1 }" @click="mainnav">主教科目</view>
        <view :class="{ common: true, act: index == 2 }" @click="funav">辅教科目</view>
      </view>
    </view>
    <!-- 列表 -->
    <scroll-view scroll-y="true" style="box-sizing: border-box; width: 100%; height: 1100rpx" @scrolltolower="more">
      <view class="list">
        <view class="item" v-for="item in list" :key="item.id" @click="goorderdetail(item.id)">
          <image :src="imgUrl + item.avatar" mode="aspectFill" style="width: 186rpx; height: 186rpx"></image>
          <view class="right">
            <view class="name">
              <view style="font-size: 30rpx; font-family: PingFang SC, PingFang SC; font-weight: bold; color: #222222">{{ item.username }}</view>
              <image :src="`../../static/icon/${item.gender == 1 ? 'nv' : 'nan'}.png`" mode="" style="width: 42rpx; height: 42rpx"></image>
              <view class="school" v-if="item.school != ''">{{ item.school }}</view>
            </view>
            <view class="subject">{{ item.grade_name + ' | ' + item.subject_name }}</view>
            <view class="long">
              <view style="font-size: 28rpx; font-family: PingFang SC, PingFang SC; font-weight: 500; color: #222222">{{ item.distance }}km</view>
              <view class="jiedan" @click.stop="reciveorder(item.id)">立即接单</view>
            </view>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      imgUrl: '', // 配置全局的图片基地址
      index: 1,
      list: [], //数据列表
      page: 1 // 分页
    };
  },
  methods: {
    // 获取数据列表
    async getlist() {
      const res = await uni.$http.post('/teacher_order/orderTaking', {
        bishop: this.index,
        page: this.page
      });
      if (res.data.data.list.length != 0) {
        this.list.push(...res.data.data.list);
      } else {
        return uni.showToast({
          title: '数据已加载完毕',
          icon: 'none'
        });
      }
    },
    // 加载更多数据
    more() {
      this.page++;
      this.getlist();
    },
    // 跳转到订单详情
    goorderdetail(id) {
      uni.navigateTo({
        url: '/teacher/orderdetail/orderdetail?id=' + id
      });
    },
    // 立即接单
    async reciveorder(id) {
      const res = await uni.$http.post('/teacher_order/takingOrder', {
        order_id: id
      });
      uni.showToast({
        title: res.data.msg,
        icon: 'none'
      });
      if (res.data.code == 1) {
        this.page = 1;
        this.list = [];
        this.getlist();
      }
    },
    // 切换导航栏
    mainnav() {
      this.index = 1;
      this.page = 1;
      this.list = [];
      this.getlist();
    },
    // 切换导航栏
    funav() {
      this.index = 2;
      this.page = 1;
      this.list = [];
      this.getlist();
    }
  },
  onLoad() {
    // // 获取数据列表
    // this.getlist();
    // 配置全局图片基地址
    this.imgUrl = this.imgurl;
  },
  onShow() {
    this.page = 1;
    this.list = [];
    this.getlist();
  }
};
</script>

<style lang="scss" scoped>
.container {
  box-sizing: border-box;
  .header {
    width: 750rpx;
    height: 100rpx;

    background: #3553e8;
    .common {
      font-size: 26rpx;
      font-family: PingFang SC, PingFang SC;
      font-weight: 500;
      color: #ffffff;
    }
    .act {
      font-size: 28rpx;
      border-bottom: 6rpx solid #fff;
    }
  }
  .list {
    box-sizing: border-box;
    margin: 30rpx;
    .item {
      display: flex;
      width: 690rpx;
      height: 186rpx;
      margin-bottom: 40rpx;
      .right {
        flex: 1;
        margin-left: 20rpx;
        .name {
          display: flex;
          .school {
            font-size: 22rpx;
            font-family: PingFang SC, PingFang SC;
            font-weight: 500;
            width: 172rpx;
            height: 40rpx;
            background: #eaedfd;
            border-radius: 10rpx 10rpx 10rpx 10rpx;
            color: #3553e8;
            text-align: center;
            line-height: 40rpx;
            text-overflow: ellipsis;
            white-space: nowrap;
            overflow: hidden;
          }
        }
        .subject {
          font-size: 26rpx;
          font-family: PingFang SC, PingFang SC;
          font-weight: 500;
        }
        .long {
          display: flex;
          align-items: center;
          justify-content: space-between;
          margin-top: 18rpx;
          .jiedan {
            box-sizing: border-box;
            width: 160rpx;
            height: 60rpx;
            text-align: center;
            line-height: 60rpx;
            font-size: 28rpx;
            color: #fff;
            background: #3553e8;
            border-radius: 100rpx 100rpx 100rpx 100rpx;
          }
        }
      }
    }
  }
}
</style>
